import request from '@/utils/request'

// 查询报警记录列表
export function listAlarm(query) {
  return request({
    url: '/campus/alarm/list',
    method: 'get',
    params: query
  })
}

// 查询报警记录详细
export function getAlarm(alarmId) {
  return request({
    url: '/campus/alarm/' + alarmId,
    method: 'get'
  })
}

// 查询报警记录详细（包含关联信息）
export function getAlarmDetail(alarmId) {
  return request({
    url: '/campus/alarm/detail/' + alarmId,
    method: 'get'
  })
}

// 查询待处理的报警记录
export function listPendingAlarms(schoolId) {
  return request({
    url: '/campus/alarm/pending',
    method: 'get',
    params: { schoolId }
  })
}

// 查询紧急报警记录
export function listEmergencyAlarms(schoolId) {
  return request({
    url: '/campus/alarm/emergency',
    method: 'get',
    params: { schoolId }
  })
}

// 查询实时报警数据（最近24小时）
export function listRealtimeAlarms(schoolId) {
  return request({
    url: '/campus/alarm/realtime',
    method: 'get',
    params: { schoolId }
  })
}

// 查询超时未处理的报警记录
export function listTimeoutAlarms(timeoutMinutes = 60) {
  return request({
    url: '/campus/alarm/timeout',
    method: 'get',
    params: { timeoutMinutes }
  })
}

// 统计报警数据
export function getAlarmStatistics(params) {
  return request({
    url: '/campus/alarm/statistics',
    method: 'get',
    params
  })
}

// 按时间段统计报警数量
export function getTimeStatistics(params) {
  return request({
    url: '/campus/alarm/statistics/time',
    method: 'get',
    params
  })
}

// 按报警类型统计
export function getTypeStatistics(params) {
  return request({
    url: '/campus/alarm/statistics/type',
    method: 'get',
    params
  })
}

// 按地理位置统计报警热点
export function getAlarmHotspots(params) {
  return request({
    url: '/campus/alarm/statistics/hotspots',
    method: 'get',
    params
  })
}

// 新增报警记录
export function addAlarm(data) {
  return request({
    url: '/campus/alarm',
    method: 'post',
    data: data
  })
}

// 修改报警记录
export function updateAlarm(data) {
  return request({
    url: '/campus/alarm',
    method: 'put',
    data: data
  })
}

// 删除报警记录
export function delAlarm(alarmId) {
  return request({
    url: '/campus/alarm/' + alarmId,
    method: 'delete'
  })
}

// 分配报警处理人
export function assignAlarmHandler(alarmId, handlerUserId) {
  return request({
    url: '/campus/alarm/assign',
    method: 'put',
    params: { alarmId, handlerUserId }
  })
}

// 开始处理报警
export function startHandleAlarm(alarmId) {
  return request({
    url: '/campus/alarm/startHandle',
    method: 'put',
    params: { alarmId }
  })
}

// 完成报警处理
export function completeAlarmHandle(alarmId, handleResult) {
  return request({
    url: '/campus/alarm/completeHandle',
    method: 'put',
    params: { alarmId, handleResult }
  })
}

// 关闭报警
export function closeAlarm(alarmId, closeReason) {
  return request({
    url: '/campus/alarm/close',
    method: 'put',
    params: { alarmId, closeReason }
  })
}

// 转接报警
export function transferAlarm(alarmId, newHandlerUserId, transferReason) {
  return request({
    url: '/campus/alarm/transfer',
    method: 'put',
    params: { alarmId, newHandlerUserId, transferReason }
  })
}

// 升级报警等级
export function upgradeAlarmLevel(alarmId, newLevel, upgradeReason) {
  return request({
    url: '/campus/alarm/upgrade',
    method: 'put',
    params: { alarmId, newLevel, upgradeReason }
  })
}

// 批量更新报警状态
export function updateAlarmStatusBatch(alarmIds, handleStatus, handlerUserId) {
  return request({
    url: '/campus/alarm/updateStatusBatch',
    method: 'put',
    params: {
      alarmIds: alarmIds.join(','),
      handleStatus,
      handlerUserId
    }
  })
}

// 导出报警记录
export function exportAlarm(query) {
  return request({
    url: '/campus/alarm/export',
    method: 'post',
    data: query
  })
} 